package com.jamila.scancode.controller;

import com.jamila.scancode.entity.BasicInfo;
import com.jamila.scancode.result.Result;
import com.jamila.scancode.service.BasicInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JAMILA
 * @since 2024-03-30 01:42:05
 */
@Api(tags = "基本信息控制器")
@RestController
@RequestMapping("/basicInfo")
public class BasicInfoController {
    @Autowired
    private BasicInfoService basicInfoService;


    @ApiOperation("保存用户基本信息")
    @PostMapping("save")
    public Result save(@RequestBody BasicInfo basicInfo){
        //根据手机号判断是否已存在基本信息；若存在则执行更新操作；若不存在则执行保存操作
        boolean save = basicInfoService.saveData(basicInfo);
        return save?Result.ok():Result.fail().message("保存基本信息失败");
    }

    @ApiOperation("根据手机号查询基本信息")
    @GetMapping("getBasicInfo/{tel}")
    public Result getBasicInfo(@PathVariable String tel){
        BasicInfo basicInfo=basicInfoService.getBasicInfo(tel);
        return basicInfo!=null?Result.ok(basicInfo):Result.ok().message("获取基本信息失败");
    }

}
